// import { BasicLayout } from '@/layouts'

import BlankLayout from "@/layout/blankLayout.vue";
const layout = () => import("@/layout");

export const staticRoutes = [
  {
    path: "/",
    component: layout,
    children: [
      {
        path: "",
        redirect: "/home",
        // roles: ["admin", "user"],
      },
      {
        path: "/home",
        name: "home",
        component: () => import("@/views/home/index"),
        roles: ["admin", "user"],
        meta: {
          title: "部门架构",
          icon: "apartment",
        },
        children: [],
      },
    ],
  },
];
export const routerMap = [
  {
    path: "/",
    component: layout,
    children: [
      {
        path: "",
        redirect: "/home",
        // roles: ["admin", "user"],
      },
      {
        path: "/home",
        name: "home",
        component: () => import("@/views/home/index"),
        roles: ["admin", "user"],
        meta: {
          title: "部门架构",
          icon: "apartment",
        },
        children: [],
      },
      {
        path: "/user",
        name: "user",
        redirect: "/user/user_item_one",
        roles: ["admin", "user"],
        meta: {
          title: "用户列表",
          icon: "user",
        },
        component: BlankLayout,
        children: [
          {
            path: "/user/user_item_one",
            name: "userItemOne",
            roles: ["admin", "user"],
            meta: {
              title: "二级菜单1",
            },
            component: () => import("@/views/user/userItemOne"),
          },
          {
            path: "/user/user_item_two",
            name: "userItemTwo",
            roles: ["admin", "user"],
            meta: {
              title: "二级菜单2",
            },
            component: () => import("@/views/user/userItemTwo"),
          },
        ],
      },
      {
        path: "/apply",
        name: "apply",
        redirect: "/apply/apply_item_one",
        roles: ["admin"],
        meta: {
          title: "应用列表",
          icon: "appstore",
        },
        component: BlankLayout,
        children: [
          {
            path: "/apply/apply_item_one",
            name: "applyItemOne",
            roles: ["admin"],
            meta: {
              title: "应用菜单1",
            },
            component: () => import("@/views/apply/applyItemOne"),
          },
          {
            path: "/apply/apply_item_two",
            name: "applyItemTwo",
            roles: ["admin"],
            meta: {
              title: "应用菜单2",
            },
            component: () => import("@/views/apply/applyItemTwo"),
          },
        ],
      },
    ],
  },
];

// 根据角色生成侧边栏菜单
export const generateSideMenu = (roles, list) => {
  const routes = [];
  const menuMap = list;
  for (let i = 0; i < menuMap.length; i++) {
    const menu = menuMap[i];
    if (menu.roles && menu.roles.includes(roles)) {
      const { children, ...info } = menu;
      const route = { ...info };
      if (children && children.length) {
        route.children = generateSideMenu(roles, children);
      }
      routes.push(route);
    }
  }
  return routes;
};
